<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>class类</h2>
</body>
<script>
    //类，对象，实例，构造器，继承，封装，多态，父类，子类，基类，派生类
   //ES5创建类，通过函数实现
//     function Person(name='无名',age=0) {
//       this.name=name

//     }
//Person.prototype.play=function() {}

//    var p1= new Person('李佳辉')
//    var p2= new Person('张星航')



   //ES6定义类
   class Person {
       constructor(name='无名',age=0) {
          this.name=name
          this.age=age
       }

       play() {
           console.log(`${this.name}喜欢打游戏`)
       }

   }

   //实例化类


    // let p1= new Person('李佳辉',23)
    // console.log('p1:',p1.name)
    //  p1.play()


    //子类
    class Chinese extends Person {
        constructor(name,age,address='北京') {
            super(name,age)  //super代表父类
            this.address=address
        }

        driveCar() {
            console.log(`${this.name}喜欢打驾驶`)
        }
    }

   let c1= new Chinese('jack',18,'河北')
   
   console.log(c1.name)
   console.log(c1.age)
   console.log(c1.address)
   c1.play()
   c1.driveCar()
 
 
</script>
</html>